Fix the root output directory when cleaning examples
authorAlex Crichton <alex@alexcrichton.com>
Thu, 20 Nov 2014 04:36:26 +0000 (20:36 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Mon, 24 Nov 2014 01:48:57 +0000 (17:48 -0800)
This forgot to take into account the logic from some other locations, so I added
a helper method!

Closes #912

src/cargo/ops/cargo_rustc/context.rs
src/cargo/ops/cargo_rustc/fingerprint.rs
src/cargo/ops/cargo_rustc/mod.rs
tests/support/mod.rs
tests/test_cargo_compile.rs

index 50cb3fb7027c07295f5e4f661c6dced12196b2b8..a743e4f91564d1aead497e6c0fc66d744244485f 100644 (file)
@@ -197,6 +197,19 @@ impl<'a, 'b: 'a> Context<'a, 'b> {
         }
     }
 
+    /// Returns the appropriate output directory for the specified package and
+    /// target.
+    pub fn out_dir(&self, pkg: &Package, kind: Kind, target: &Target) -> Path {
+        let out_dir = self.layout(pkg, kind);
+        if target.get_profile().is_custom_build() {
+            out_dir.build(pkg)
+        } else if target.is_example() {
+            out_dir.examples().clone()
+        } else {
+            out_dir.root().clone()
+        }
+    }
+
     /// Return the (prefix, suffix) pair for dynamic libraries.
     ///
     /// If `plugin` is true, the pair corresponds to the host platform,
index 09a6f605ea1bff57e27d3ef78dba644445feb821..c842fbe89e21057521b9c004f2163a7a1b69d65b 100644 (file)
@@ -82,16 +82,7 @@ pub fn prepare_target(cx: &mut Context, pkg: &Package, target: &Target,
     };
     let is_rustc_fresh = try!(is_fresh(&loc, rustc_fingerprint.as_slice()));
 
-    let root = {
-        let layout = cx.layout(pkg, kind);
-        if target.get_profile().is_custom_build() {
-            layout.build(pkg)
-        } else if target.is_example() {
-            layout.examples().clone()
-        } else {
-            layout.root().clone()
-        }
-    };
+    let root = cx.out_dir(pkg, kind, target);
     if !target.get_profile().is_doc() {
         for filename in try!(cx.target_filenames(target)).iter() {
             let dst = root.join(filename);
index 5c4a00befda6e42cc72fba8e64b82c5e73f581b3..5d71f605f3f44d285f0777425f6a33d757b30bee 100644 (file)
@@ -387,7 +387,7 @@ fn rustc(package: &Package, target: &Target,
         let rustc = if show_warnings {rustc} else {rustc.arg("-Awarnings")};
 
         let filenames = try!(cx.target_filenames(target));
-        let root = cx.layout(package, kind).root().clone();
+        let root = cx.out_dir(package, kind, target);
 
         // Prepare the native lib state (extra -L and -l flags)
         let build_state = cx.build_state.clone();
@@ -634,17 +634,8 @@ fn build_base_args(cx: &Context,
 
 fn build_plugin_args(mut cmd: ProcessBuilder, cx: &Context, pkg: &Package,
                      target: &Target, kind: Kind) -> ProcessBuilder {
-    let out_dir = cx.layout(pkg, kind);
-    let out_dir = if target.get_profile().is_custom_build() {
-        out_dir.build(pkg)
-    } else if target.is_example() {
-        out_dir.examples().clone()
-    } else {
-        out_dir.root().clone()
-    };
-
     cmd = cmd.arg("--out-dir");
-    cmd = cmd.arg(out_dir);
+    cmd = cmd.arg(cx.out_dir(pkg, kind, target));
 
     let dep_info_loc = fingerprint::dep_info_loc(cx, pkg, target, kind);
     cmd = cmd.arg("--dep-info").arg(dep_info_loc);
index 31fb1350e4697d20a05640cd9e6264bce4bbe791..3c0de8f55f8b3c3918ce024cb2676fe51d8741da 100644 (file)
@@ -517,5 +517,3 @@ pub static PACKAGING:   &'static str = "   Packaging";
 pub static DOWNLOADING: &'static str = " Downloading";
 pub static UPLOADING:   &'static str = "   Uploading";
 pub static VERIFYING:   &'static str = "   Verifying";
-#[allow(dead_code)]
-pub static WARNING:     &'static str = "     Warning";
index 5568c941e7e82d1c9b8261cbb568ff36d129aa12..e36a4a09d1aabca37471f9428f1fc58f07a9ffa0 100644 (file)
@@ -1470,3 +1470,29 @@ test!(cargo_platform_specific_dependency_wrong_platform {
     let lockfile = File::open(&lockfile).read_to_string().assert();
     assert!(lockfile.as_slice().contains("bar"))
 })
+
+test!(example_bin_same_name {
+    let p = project("foo")
+        .file("Cargo.toml", r#"
+            [package]
+            name = "foo"
+            version = "0.0.1"
+            authors = []
+        "#)
+        .file("src/main.rs", "fn main() {}")
+        .file("examples/foo.rs", "fn main() {}");
+
+    p.cargo_process("test").arg("--no-run")
+        .exec_with_output()
+        .assert();
+
+    assert_that(&p.bin("foo"), existing_file());
+    assert_that(&p.bin("examples/foo"), existing_file());
+
+    p.process(cargo_dir().join("cargo")).arg("test").arg("--no-run")
+        .exec_with_output()
+        .assert();
+
+    assert_that(&p.bin("foo"), existing_file());
+    assert_that(&p.bin("examples/foo"), existing_file());
+})